package com.itheima.d01_properties;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

/**
 * 目标：掌握Properties属性文件的数据解析
 */
public class Test {

    public static void main(String[] args) throws Exception {
        //需求：读取users.properties属性文件中的用户信息
        //1.创建Properties对象
        Properties pro = new Properties();

        //2.将指定的属性文件加载到Properties对象中
        pro.load(new FileInputStream("day12_properties_xml_log\\src\\com\\itheima\\d01_properties\\users.properties"));

        //3.获取数据：Properties就是一个Map集合
        //方式一：键找值
        System.out.println(pro.getProperty("zhangsan"));
        System.out.println(pro.getProperty("lisi"));
        System.out.println(pro.getProperty("admin"));

        System.out.println("=================");
        //方式二：键值对
        Set<Map.Entry<Object, Object>> entries = pro.entrySet();
        for (Map.Entry<Object, Object> entry : entries) {
            System.out.println(entry.getKey() + "=" + entry.getValue());
        }

        System.out.println("=================");
        //方式三：lambda
        pro.forEach((k,v)-> System.out.println(k+"="+v));
    }
}
